package cn.edu.nit.sys.service.impl;

import cn.edu.nit.sys.entity.Score;
import cn.edu.nit.sys.mapper.ScoreMapper;
import cn.edu.nit.sys.service.ScoreService;
import cn.edu.nit.sys.utils.R;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author 罗文斌
 * @Date 2023/5/10
 * @Version 1.0.0
 */
@Service
public class ScoreServiceImpl extends ServiceImpl<ScoreMapper, Score> implements ScoreService {

    @Override
    public R getGradeList(String id) {
        List<String> list = baseMapper.getGradeList(id);
        List<Map<String, String>> subjectList = baseMapper.getSubjectList(id);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("grade", list);
        jsonObject.put("subject", subjectList);
        return R.ok(jsonObject);
    }

    @Override
    public R getList(Page<Score> page, String siftId, String siftSubject, String siftTime) {
        Page<Score> list = baseMapper.getList(page, siftId, siftSubject, siftTime);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("total", list.getTotal());
        jsonObject.put("list", list.getRecords());
        return R.ok(jsonObject);
    }

    @Override
    public R getStudentList(String subjectId, String name) {
        List<Map<String, String>> studentList = baseMapper.getStudentList(subjectId, name);
        return R.ok(studentList);
    }

    @Override
    public R getUserScore(String id) {
        List<Map<String,String>> list = baseMapper.getUserScore(id);
        return R.ok(list);
    }
}
